<template>
     <el-dialog
    v-model="dialogVisible"
    title="批量添加"
    width="500"
    :before-close="handleClose"
  >
     <el-upload
    ref="uploadRef"
    class="upload-demo"
    action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
    :auto-upload="false"
    :limit="1"
      :on-exceed="handleExceed"
  >
    <template #trigger>
      <el-button type="primary">选择文件</el-button>
    </template>

    <!-- <el-button class="ml-3" type="success" @click="submitUpload">
      upload to server
    </el-button> -->

    <template #tip>
      <div class="el-upload__tip">
        jpg/png files with a size less than 500kb
      </div>
    </template>
  </el-upload>
  <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="save()">
          上传
        </el-button>
      </div>
    </template>
</el-dialog>
  
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import type { UploadInstance,ElMessage } from 'element-plus'
import type { UploadProps } from 'element-plus'
const props = defineProps({
  visiable: Boolean,   
})
const dialogVisible = ref(props.visiable);

const emit1 = defineEmits(['updateVisiable2'])
const uploadRef = ref<UploadInstance>()
const handleExceed: UploadProps['onExceed'] = (files, uploadFiles) => {
  ElMessage.warning(
    `只允许上传1个文件！`
  )
}
 
const handleClose = (done: () => void) => {
 emit1('updateVisiable2',false);
}
const save = () => {
  uploadRef.value!.submit()
  emit1('updateVisiable2',false);
}
</script>